#ifndef _PROTOCAL_H_
#define _PROTOCAL_H_
#include<windows.h>
#include "RadioData.h"
#include "ProtocalDef.h"

#define SetBit(Var,Place) (Var|=(1<<Place))
#define ClrBit(Var,Place) (Var&=(1<<Place)^255)
#define ValBit(Var,Place) (Var& (1<<Place))
class CProtocal
{
public:
	CProtocal(void);
    virtual ~CProtocal(void);
public:
	void M2A_InitOkCmd(BYTE *RcvData,long RcvLength);
	void M2A_McuPowerCmd(BYTE *RcvData,long RcvLength);
	void M2A_ModeHarwardSwitch(BYTE *RcvData,long RcvLength);
	void M2A_ModeFunSwitch(BYTE *RcvData,long RcvLength);
	void M2A_EnableScreenSaveCmd(BYTE *RcvData,long RcvLength);
	void M2A_ModeChangeCmd(BYTE *RcvData,long RcvLength);
	void M2A_ForceSourceCmd(BYTE *RcvData,long RcvLength);
	void M2A_NavOtherMenuChangeCmd(BYTE *RcvData,long RcvLength);
	void M2A_VideoSignalOk(BYTE *RcvData,long RcvLength);
	void M2A_MpegLoadingOk(BYTE *RcvData,long RcvLength);
	void M2A_ParameterChangeCmd(BYTE *RcvData,long RcvLength);
	void M2A_TimeChangeCmd(BYTE *RcvData,long RcvLength);
	void M2A_AudioRefAdjCmd(BYTE *RcvData,long RcvLength);
	void M2A_KeyPressCmd(BYTE *RcvData,long RcvLength);
	void M2A_SteerKeyCmd(BYTE *RcvData,long RcvLength);
	void M2A_SteerKeyVoltageCmd(BYTE *RcvData,long RcvLength);
	void M2A_SystemSetup(BYTE *RcvData,long RcvLength);
public:
	void TxMcuInitOKCmd();
	BOOL TxMcuKeyReqEx(BYTE bModeID, BYTE vKey);
	void TxMcuTunerChangeCmd(BYTE HiValue, BYTE LoValue);
	BOOL TxMcuSetPublicParameter(BYTE bReference, BYTE bReferenceValue);
	void TxMcuSystemSetup(BYTE bReference, BYTE bReferenceValue);
	void TxMcuSWCKeyCmd(BYTE bReference, BYTE bReferenceValue);
	void TxMcuSWCEntryCmd(BYTE bReference);
	void TxMcuSWCResetCmd(BYTE bReference);
	void TxMcuSourceReq(BYTE bReferenceValue);
	void TxMcuForceGpsVideoCmd(BYTE bModeID,BYTE bReferenceValue);
	void TxMcuTouchCoordinateCmd(BYTE bModeID, DWORD xPos, DWORD yPos);
	void TxMcuTouchReleaseCmd(BYTE bModeID);

	void RxCommonSystemHandler(BYTE *RcvData,long RcvLength);
	void RxGeneralSetupCmd(BYTE *RcvData,long RcvLength);
	void RxSteerKeyVoltageCmd(BYTE *RcvData,long RcvLength);
	void RxSteerKeyCmd(BYTE *RcvData,long RcvLength);
	BYTE* CheckTxFrame(BYTE* RcvData,long RcvLength);
	void BinaryCmdAndSend(BYTE *pCmd, DWORD dwLength);
public:
	CRadioData		m_RadioData;
    PROTOCAL_INFO	m_ComSystemData;
	SOURCE_MODE				m_CurrSourceMode;
//Radio Tuner
	TB_RadioData_CbkFunc	*m_pRadioDataCbkFunc;
//Common System	
	TB_ComSystem_CbkFunc	*m_pComSystemCbkFunc;
//Common Balance
	TB_ComBalance_CbkFunc	*m_pComBalanceCbkFunc;
//Setup	
	TB_Setup_CbkFunc		*m_pSetupCbkFunc;
//SWC
	TB_SWC_CbkFunc			*m_pSWCCbkFunc;
//Source Change
	TB_SOURCE_CbkFunc		*m_pSourceCbkFunc;
//MPEG
	TB_MPEG_CbkFunc			*m_pMpegCbkFunc;
//EmptyWnd
	TB_EmptyWnd_CbkFunc		*m_pEmptyWndCbkFunc;
//Startup Wnd
	TB_StartupWnd_CbkFunc	*m_pStartupWndCbkFunc;
public:
	static DWORD CreateTimeIntervalThread(LPVOID pParam );
	HANDLE				m_gTimeInterval;

};
#endif